from django.db import models

# ip-to-country
class IpToCountry(models.Model):
    IP_FROM = models.PositiveIntegerField()
    IP_TO = models.PositiveIntegerField()
    COUNTRY_CODE2 = models.CharField(max_length = 2)
    COUNTRY_CODE3 = models.CharField(max_length = 3)
    COUNTRY_NAME = models.CharField(max_length = 50)     

    def __unicode__(self):
        return "%s %s %s" % (self.IP_FROM ,self.IP_TO, self.COUNTRY_NAME) 
    
   #def import_csv(self, file):
   #    import csv
   #        # First delete all the objects before inserting
   #    IpToCountry.objects.all().delete()
   #            # create a reader to get the data from the file
   #    reader = csv.reader(open(file))
   #    count = 0    
   #    for ipf, ipt, cc2, cc3, cname in reader:
   #        count += 1          
   #        object = IpToCountry(count,ipf, ipt, cc2, cc3, cname)
   #        object.save()
   #        if count % 10000 == 0:
   #            print count
   #    print count , "inserted. :)"
   #    del reader